package jsr166.contrib.uncontended;

import java.util.ListIterator;
import java.util.concurrent.locks.ReadWriteLock;

 class ReadWriteLockedListIterator<E>  extends ReadWriteLockedIterator<E, ListIterator<E>> implements ListIterator<E> {

    ReadWriteLockedListIterator(ListIterator<E> base, ReadWriteLock rwLock) {
        super(base, rwLock);
    }
    
    public void add(E arg0) {
        rwLock.writeLock().lock();
        try {
        lock.lock();
        try {
              base.add(arg0);
        } finally {
            lock.unlock();
        }} finally {
            rwLock.writeLock().unlock();
        }
    }

    public boolean hasPrevious() {
        rwLock.readLock().lock();
        try {
        lock.lock();
        try {
              return base.hasPrevious();
        } finally {
            lock.unlock();
        }} finally {
            rwLock.readLock().unlock();
        }
    }

    public int nextIndex() {
        rwLock.readLock().lock();
        try {
        lock.lock();
        try {
              return base.nextIndex();
        } finally {
            lock.unlock();
        }} finally {
            rwLock.readLock().unlock();
        }
    }

    public E previous() {
        rwLock.readLock().lock();
        try {
        lock.lock();
        try {
              return base.previous();
        } finally {
            lock.unlock();
        }} finally {
            rwLock.readLock().unlock();
        }
    }

    public int previousIndex() {
        rwLock.readLock().lock();
        try {
        lock.lock();
        try {
              return base.previousIndex();
        } finally {
            lock.unlock();
        }} finally {
            rwLock.readLock().unlock();
        }
    }

    public void set(E arg0) {
        rwLock.writeLock().lock();
        try {
        lock.lock();
        try {
               base.set(arg0);
        } finally {
            lock.unlock();
        }} finally {
            rwLock.writeLock().unlock();
        }
    }

}
